package com.tsd.jxc.fin.controller;

import com.tsd.common.controller.BaseController;
import com.tsd.common.entity.CommonParameterValueExt;
import com.tsd.core.vo.ErrorCode;
import com.tsd.core.vo.HttpResult;
import com.tsd.jxc.fin.service.JxcFinanceAccountTypeService;
import com.tsd.system.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 描述：账单类型控制层
 *
 * @author Hillpool
 * @date 2022/09/02 16:42:49
 */
@Controller
@Scope("prototype")
@RequestMapping("/api/v2")
@Api(tags = "进销存-账单类型", description = "账单类型的API描述")
public class JxcFinanceAccountTypeController extends BaseController {

    @Resource
    private JxcFinanceAccountTypeService jxcFinanceAccountTypeService;

    @ApiOperation(value = "保存账单类型", notes = "保存账单类型")
    @ResponseBody
    @RequestMapping(value = "/saveJxcFinanceAccountType.action", method = RequestMethod.POST)
    public HttpResult<Object> saveJxcFinanceAccountType() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            SysUser opUser = super.getSysUser();
            CommonParameterValueExt valueExt = super.getParams(request, CommonParameterValueExt.class);
            jxcFinanceAccountTypeService.saveJxcFinanceAccountType(valueExt, opUser);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "保存账单类型", notes = "保存账单类型")
    @ResponseBody
    @RequestMapping(value = "/deleteJxcFinanceAccountType.action", method = RequestMethod.POST)
    public HttpResult<Object> deleteJxcFinanceAccountType() {
        HttpResult<Object> hr = new HttpResult<>();
        try {
            SysUser opUser = super.getSysUser();
            List<String> list = super.getParamsList("sids", String.class, true);
            jxcFinanceAccountTypeService.deleteJxcFinanceAccountType(list, opUser);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }
}
